package cn.gson.boot.controller;

import cn.gson.boot.model.mapper.ChuKuMapper;
import cn.gson.boot.model.pojos.*;
import cn.gson.boot.model.service.CaringService;
import cn.gson.boot.model.service.ChRuKuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/crku")
public class ChuRuKuController {
    @Autowired
    ChRuKuService chRuKuService;

    //查看所有出库
    @RequestMapping("/selectAllChuKu")
    @ResponseBody
    public List<Chuku> selectAllChuKu(String ckHao,String ckTime){
        String time3 = null;
        if(ckTime != null && ckTime != "" && !ckTime.equals("")){
            StringBuffer time1 = new StringBuffer(ckTime.substring(0,10));
            int ti = Integer.parseInt(time1.substring(8))+1;
            String tistr = toString().valueOf(ti);
            if(toString().valueOf(ti).length() == 1){
                tistr = 0 + toString().valueOf(ti);
            }
            StringBuffer time2 = new StringBuffer(time1.replace(8,time1.length(), tistr));
            System.err.println("tim2:"+time2);
            time3 = time2.toString();
        }
        return chRuKuService.selectAllChuKu(ckHao,time3);
    }
    /*public Map<String,Object> selectAllChuKu(String ckHao,String ckTime,Integer pageNumm, Integer pageSizee){
        Page<Object> objects = PageHelper.startPage(pageNumm, pageSizee);
        String time3 = null;
        if(ckTime != null && ckTime != "" && !ckTime.equals("")){
            StringBuffer time1 = new StringBuffer(ckTime.substring(0,10));
            int ti = Integer.parseInt(time1.substring(8))+1;
            String tistr = toString().valueOf(ti);
            if(toString().valueOf(ti).length() == 1){
                tistr = 0 + toString().valueOf(ti);
            }
            StringBuffer time2 = new StringBuffer(time1.replace(8,time1.length(), tistr));
            System.err.println("tim2:"+time2);
            time3 = time2.toString();
        }
        List<Chuku> list = chRuKuService.selectAllChuKu(ckHao,time3);
        Map<String,Object> map = new HashMap();
        map.put("total", objects.getTotal());
        map.put("list", list);
        return map;
    }*/

    //交付计划申请出库
    @RequestMapping("/jjsqChuku")
    @ResponseBody
    public void jjsqChuku(Integer jjId){
        chRuKuService.jjsqChuku(jjId);
    }
    //换货生成的订单申请出库
    @RequestMapping("/hhddChuku")
    @ResponseBody
    public void hhddChuku(Integer ddId){
        chRuKuService.hhddChuku(ddId);
    }
    //确定出库
    @RequestMapping("/chukuOk")
    @ResponseBody
    public void chukuOk(@RequestBody Chuku chuku){
        chRuKuService.chukuOk(chuku);
    }

    //换货确定出库
    @RequestMapping("/huanHuoChukuOk")
    @ResponseBody
    public void huanHuoChukuOk(@RequestBody Chuku chuku){
        chRuKuService.huanHuoChukuOk(chuku);
    }


    //查看所有入库
    @RequestMapping("/selectAllRuKu")
    @ResponseBody
    public List<Ruku> selectAllRuKu(String rkHao,String rkTime){
        String time3 = null;
        if(rkTime != null && rkTime != "" && !rkTime.equals("")){
            StringBuffer time1 = new StringBuffer(rkTime.substring(0,10));
            int ti = Integer.parseInt(time1.substring(8))+1;
            String tistr = toString().valueOf(ti);
            if(toString().valueOf(ti).length() == 1){
                tistr = 0 + toString().valueOf(ti);
            }
            StringBuffer time2 = new StringBuffer(time1.replace(8,time1.length(), tistr));
            System.err.println("tim2:"+time2);
            time3 = time2.toString();
        }
        List<Ruku> list = chRuKuService.selectAllRuKu(rkHao,time3);
        return list;
    }
    //确定入库
    @RequestMapping("/rukuOk")
    @ResponseBody
    public void rukuOk(@RequestBody Ruku ruku){
        chRuKuService.rukuOk(ruku);
    }

    //出库 ：查看所有订单(执行中的订单)换货 没有出库的
    @RequestMapping("/chuKuSelectAllDingDan")
    @ResponseBody
    public List<Dingdan> chuKuSelectAllDingDan(){
        return chRuKuService.chuKuSelectAllDingDan();
    }



    //根据入库id查看入库
    @RequestMapping("/selectRuKuByRkId")
    @ResponseBody
    public Ruku selectRuKuByRkId(Integer rkId){
        return chRuKuService.selectRuKuByRkId(rkId);
    }

    @Autowired
    ChuKuMapper chuKuMapper;
    //根据出库id查看出库
    @RequestMapping("/selectChuKuByCkId")
    @ResponseBody
    public Chuku selectChuKuByCkId(Integer ckId){
        return chuKuMapper.selectChuKuByCkId(ckId);
    }
}
